<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/common/taglibs.jsp" %>
<%@ page import="org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter" %>
<%@ page import="org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter" %>
<%@ page import="org.springframework.security.core.AuthenticationException" %>
<%@page import="org.springside.modules.security.springsecurity.SpringSecurityUtils"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>后台登录</title>
<%@ include file="/common/meta.jsp" %>
<link href="${ctx}/css/login.css" type="text/css" rel="stylesheet" />
<link href="${ctx}/js/validate/jquery.validate.css" type="text/css" rel="stylesheet" />
<script src="${ctx}/js/jquery.js" type="text/javascript"></script>
<script src="${ctx}/js/jquery.cookie.js" type="text/javascript"></script>
<script src="${ctx}/js/validate/jquery.validate.js" type="text/javascript"></script>
<script src="${ctx}/js/validate/messages_cn.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
	
	//聚焦第一个输入框
	$("#j_username").focus();
	initCookie();
	$("#inputForm").validate({
		rules: {
			j_username: "required", 
			j_password: "required" 
		},
		messages: {
			j_username: {
				required: "请输入用户名 "
			},
			j_password: {
				required: "请输入密码"
			} 
		},
        errorPlacement: function(error, element) {   
	        if (document.getElementById("error_"+element.attr("name")))  {
	            error.appendTo("#error_"+element.attr("name"));  
	        }
	        else       
	            error.insertAfter(element);   
	        },
	        errorElement: "em"
	}); 
});
$(function(){
	document.onkeydown = function(e){ 
	    var ev = document.all ? window.event : e;
	    if(ev.keyCode==13) {
	    	onSubmit();
	     }
	}
	}); 
function initCookie(){
	var c = $.cookie('j_username'); 
	if(c!=null){
    	$("#j_username").val(c);
    	$("#rememberMe").attr("checked","true");
	}
} 
function setCookie(){
	var username = $("#j_username").val()
	if($("#rememberMe").attr("checked") && username!=''){
		$.cookie('j_username', username, { expires: 7 }); 
	}else{
		$.cookie('j_username', null); 
	}
}
function onSubmit() {
	 if($("#inputForm").valid()){
	 	$("#inputForm").submit();
	 }	
}
document.onkeydown = function(e){    
	e = e || window.event;   
	if(e.keyCode === 13){        
	 onSubmit();   
	}
};
</script>
</head>
<body>
<div id="wrapper"> 
	<!-- 正文内容 start -->
	<div id="content">
		<div class="supertitle">
			<p><img src="${ctx}/image/top-logo.png"/> </p>
		</div>
 		<!--lgoin start -->
 		 <form method="post" id="inputForm"  action="${ctx}/j_spring_security_check">
		<div class="reg_boxnew"> 
    		<p class="login_title">欢迎登录网站后台</p>
			<form id="inputForm" name="inputForm" action="${ctx}/j_spring_security_check"  method="post">
    		<ul>
    			<li>
    				<label>用户名</label>
					<input type="text" id="j_username" name="j_username" style="width:200px;" />
    			</li>
    			<li>
    				<label>密&nbsp;&nbsp;&nbsp;码</label>
    				<input type="password" id="j_password" name="j_password" style="width:200px;" />
                </li>
                <li>
                	<span class="prompt">
                          <p class="prompt_err  ml10" >
                        	  <%
								if (session.getAttribute(AbstractAuthenticationProcessingFilter.SPRING_SECURITY_LAST_EXCEPTION_KEY) != null) {
								%>
									<font color="red">登录失败，用户名或密码错误.</font>
								<%
									session.removeAttribute(AbstractAuthenticationProcessingFilter.SPRING_SECURITY_LAST_EXCEPTION_KEY);
								}
								%>
                          </p>
                    </span>
                </li>
                <li>
                    <label style="width:20px;">
                        <input type="checkbox" name="rememberMe" id="rememberMe" value="true" onclick="setCookie();"/>
                    </label>记住我的登录名
                </li>
    		</ul>
    		<p class="btn_login_box">
    			<a onclick="onSubmit();"><img style="cursor:pointer;" onclick="onSubmit();"  src="${ctx}/image/btn-login.png" /></a>
    		</p>
    		</form>
		</div>
		</form>
		<!--lgoin end --> 
    <!--info end --> 
  </div>
  <!-- 正文内容 end --> 
<%@ include file="/common/footer.jsp" %>
</div>
</body>
</html>

